package edu.fiu.cis.objects;

import java.io.IOException;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.graphics.Canvas;
import android.graphics.Color;

import com.jwetherell.augmented_reality.R;
import com.jwetherell.augmented_reality.ui.objects.PaintableGps;
import com.jwetherell.augmented_reality.ui.objects.PaintableObject;

public class PaintableBIM extends PaintableObject{

    private float width = 0, height = 0;
    private int borderColor = Color.rgb(255, 255, 255);
    private int backgroundColor = Color.argb(128, 0, 0, 0);
    
    private ArrayList<BIMLine> lineList;

    public PaintableBIM(ArrayList<BIMLine> lineList, float width, float height) {
        this(lineList, width, height, Color.rgb(255, 255, 255), Color.argb(128, 0, 0, 0));
    }

    public PaintableBIM(ArrayList<BIMLine> lineList, float width, float height, int borderColor, int bgColor) {
        set(width, height, borderColor, bgColor);
        this.lineList = lineList;
    }

    /**
     * Set this objects parameters. This should be used instead of creating new
     * objects.
     * 
     * @param width
     *            width of the box.
     * @param height
     *            height of the box.
     */
    public void set(float width, float height) {
        set(width, height, borderColor, backgroundColor);
    }

    /**
     * Set this objects parameters. This should be used instead of creating new
     * objects.
     * 
     * @param width
     *            width of the box.
     * @param height
     *            height of the box.
     * @param borderColor
     *            Color of the border.
     * @param bgColor
     *            Background color of the surrounding box.
     */
    public void set(float width, float height, int borderColor, int bgColor) {
        this.width = width;
        this.height = height;
        this.borderColor = borderColor;
        this.backgroundColor = bgColor;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void paint(Canvas canvas) {
        if (canvas == null) throw new NullPointerException();
//
//        setFill(true);
//        setColor(backgroundColor);
//        paintRect(canvas, 0, 0, width, height);
//
//        setFill(false);
//        setColor(borderColor);
//        paintRect(canvas, 0, 0, width, height);
        setStrokeWidth(3);
        for(int i=0;i<this.lineList.size();i++)
        {
        	BIMLine line = this.lineList.get(i);
        	setColor(line.color);
        	
        	double angle = Math.PI / 4;
        	double delX = Math.cos(angle);
        	double delY = Math.sin(angle);
        	double delZ = 0.5;
        	
        	double x1 =  line.x1 * delX + line.z1* delZ;
        	double y1 = line.x1 * delX+ line.y1 * delY;
        	
        	double x2 =  line.x2 * delX + line.z2* delZ;
        	double y2 = line.x2 * delX+ line.y2 * delY;
        	
        	paintLine(canvas, (float)x1,(float)y1,(float)x2,(float)y2);
        	if(line.text.equals(""))
        	{
        		double midX = (x1+x2)/2;
            	double midY = (y1+y2)/2;
            	paintText(canvas,(float) midX,(float) midY, line.text);
        	}
            
            
        }
        
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public float getWidth() {
        return width;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public float getHeight() {
        return height;
    }
    
   
 
}
